<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>JSP</title>
    <link rel="stylesheet" href="../../css/base.css" />
	<link rel="stylesheet" href="../../css/info-mgt.css" />
	<link rel="stylesheet" href="../../css/info-reg.css" />
	<link rel="stylesheet" href="../../css/WdatePicker.css" />
	<script type="text/javascript" src="../../js/jquery.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/WdatePicker.js"></script>
	<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
	<script type="text/javascript" src="../../js/ajaxfileupload.js"></script>
  </head>
  
  <body>
    <div class="title"><h2>单位文件</h2></div>
	<div class="query">
		<div class="query-conditions ue-clear">
			<div class="conditions name ue-clear" style="width:20%;">
	            <label>文档主题:</label>
	            <div class="select-wrap">
	                <div class="select-title ue-clear">
	                	<!-- 标题text文本框 -->
	                	<input type="text" id="title" style="width:100%; border:0px solid red;" placeholder="请输入姓名" />
	                </div>
	            </div>
	        </div>
	        <div class="conditions time ue-clear" style="width:19%;">
	            <label>上传时间:</label>
	            <div class="time-select">
	            	<input id="startTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="开始时间" />
	                <i class="icon"></i>
	            </div>
	            <span class="line">-</span>
	            <div class="time-select">
	            	<input id="endTime" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="结束时间" />
	                <i class="icon"></i>
	            </div>
	        </div>
	    </div>
	    <div class="query-btn ue-clear">
	    	<a href="javascript:;" class="confirm">查询</a>
	        <a href="javascript:;" class="clear">清空条件</a> 
	    </div>
	</div>
	<div class="table-box">
		<table>
	    	<thead>
	        	<tr>
	            	<th class="num">上传时间</th>
	            	<th class="name">上传人</th>
	                <th class="name">文档主题</th>
	                <th class="operate">操作</th>
	            </tr>
	        </thead>
	        <tbody id="FilesTbody">
	        	<!-- 个人文件表格 -->
	        </tbody>
	    </table>
	</div>
	<!-- 分页按钮 ------------------------------------------------->
	<div style="margin:0px auto; width:100%; text-align:center;">
	  	<table id="tableLast" width="80%" align="center" border="0">
	  		<tr align="center">
	  			<td width="75%"></td>
	  			<td><a href="javascript:void(0);" id="headPage">首页</a></td>
	  			<td><a href="javascript:void(0);" id="backPage">上一页</a></td>
	  			<td align="right">当前页面:</td>
	  			<td width="8%" align="left"><input type="text" id="page" value="1" style="width:20%;">
	  				<a href="javascript:void(0);" id="skipPage">跳转</a>&nbsp;&nbsp;
	  				<label id="nowPage">1</label>/<label id="countPage"></label>
	  			</td>
	  			<td><a href="javascript:void(0);" id="nextPage">下一页</a></td>
	  			<td><a href="javascript:void(0);" id="lastPage">末页</a></td>
	  		</tr>
	  	</table>
	  	<br/>
  	</div>
  	
  	<script type="text/javascript">
  		//删除
  		function DelFile(i){
  			var id=$("#fileId"+i).val();
  			if(window.confirm("确认删除该文件吗?")){
  				//异步
  				$.ajax({
  				 type:"POST",
			 	 url:"companyFileManager.action?method=delFile",
			 	 data:"id="+id,
			 	 success:function(msg){
			 	 	alert("删除成功");
			 	 	$("#fileTr"+i).replaceWith("<tr><td class='name'> - </td></tr>");
			 	 }
  				});
  			}
  		}
	  	
  	$(function(){
	  	//查询字符串
  		var condition="";
  		var username="${login_User.userName }";
  		var userId="${login_User.userId }";
  		var term="";
  		var other="&file_type=company";
		//异步查找个人文档
		function paging(condition){
			if(isCondition){
				var title=$("#title").val();
				var startTime=$("#startTime").val();
				var endTime=$("#endTime").val();
				if(title!=""){
					term+="&file_topic="+title;
				}
				//拼接时间查询字符串
				if(startTime!=""&&endTime!=""){
					term+="&file_time="+startTime+","+endTime;
				}else if(startTime!=""&&endTime==""){
					term+="&file_time="+startTime+",8888-08-08";
				}else if(startTime==""&&endTime!=""){
					term+="&file_time=1111-11-11,"+endTime;
				}
			}
			$.ajax({
			 type:"POST",
			 url:"accLwg*FileDocument.paging",
			 data:condition+other+term,
			 success:function(msg){
			 	term="";
			 	var str="";
			 	for(var i=0;i<msg.data.length;i++){
			 		str+="<tr id='fileTr"+i+"'><input type='hidden' id='fileId"+i+"' value='"+msg.data[i].fileId+"' />";
			 		str+="<td width='20%' class='num'>"+msg.data[i].fileTime+"</td>";
			 		str+="<td width='20%' class='num'>"+msg.data[i].fileUserName+"</td>";
			 		str+="<td width='20%'  class='name'><a id='fileName"+i+"' href='${pageContext.request.contextPath }/"+msg.data[i].fileText+"'>"+msg.data[i].fileTopic+"</a></td>";
		            str+="<td width='20%' class='operate'>";
		            //判断是否为自己上传的文档
		            if(msg.data[i].fileUserid==userId){
		            	str+="<a id='DelFile"+i+"' href='javascript:void(0);' onclick='DelFile("+i+")' >删除<a/>";
		            }else{
		            	str+="<a>无</a>";
		            }	
		            str+="</td></tr>";
			 	}
			 	if(i<10){
			 		for(;i<10;i++){
			 			str+="<tr><td class='name'> - </td></tr>";
			 		}
			 	}
			 	$("#FilesTbody").html(str);
			 	//向上取整总页数
				$("#countPage").text(Math.ceil(msg.rowNum/15));
			 }
			});
		}
		//调用分页
		condition="nowPage=0&turnType=next";
		paging(condition);
		
		
		//首页
		$("#headPage").click(function(){
			if($("#nowPage").text()==1){
			}else{
				data="nowPage=0&turnType=next";
				paging(data);
				$("#nowPage").text(1);
				$("#page").val(1);
			}
		});
		//末页
		$("#lastPage").click(function(){
			if($("#nowPage").text()==$("#countPage").text()){
			}else{
				data="nowPage="+(parseInt($("#countPage").text())-1)+"&turnType=next";
				paging(data);
				$("#nowPage").text($("#countPage").text());
				$("#page").val($("#nowPage").text());
			}
		});
		//上一页
		$("#backPage").click(function(){
			if($("#nowPage").text()==1){
			}else{
				data="nowPage="+$("#nowPage").text()+"&turnType=back";
				paging(data);
				$("#nowPage").text(parseInt($("#nowPage").text())-1);
				$("#page").val($("#nowPage").text());
			}
		});
		//下一页
		$("#nextPage").click(function(){
			if($("#nowPage").text()==$("#countPage").text()){
			}else{
				data="nowPage="+$("#nowPage").text()+"&turnType=next";
				paging(data);
				$("#nowPage").text(parseInt($("#nowPage").text())+1);
				$("#page").val($("#nowPage").text());
			}
		});
		//跳转页面
		$("#skipPage").click(function(){
			if($("#page").val()>$("#countPage").text()||$("#page").val()<1||
			$("#page").val()==$("#nowPage").text()){
			}else{
				data="nowPage="+(parseInt($("#page").val())-1)+"&turnType=next";
				paging(data);
				$("#nowPage").text($("#page").val());
			}
		});
		
		//清空按钮
		$(".clear").click(function(){
			$("#title").val("");
			$("#startTime").val("");
			$("#endTime").val("");
			isCondition=false;
			
		});
		var isCondition=false;//是否使用查询条件
		//查询按钮
		$(".confirm").click(function(){
			//调用分页
			isCondition=true;
			condition="nowPage=0&turnType=next";
			paging(condition);
		});
	});	
  		
  		
  		
  		
  		
  	//改变分页按钮字体大小
	$("#tableLast tr td").css("font-size","15px");
	$("#tableLast tr td").css("background","url(../../images/righttitlebig.png)");
	
	$("tbody").find("tr:odd").css("backgroundColor","#eff6fa");
	
	showRemind('input[type=text], textarea','placeholder');
	//样式
	$("tbody").find("tr:odd").css("backgroundColor","#eff6fa");
	showRemind('input[type=text], textarea','placeholder');
  	</script>
  	
  	
  </body>
</html>
